Repository navigation
Add PhayaThaiBERT POS tagger (ONNX and Transformers) - #1550
Merged
Merged
Conversation
Member
|
@wiriyabot Thank you for pull request! Can you sent this pull request to dev branch? |
Add the nlp-chula/phayathaibert-thai-pos-tagger model, fine-tuned on the TUD treebank, as a Universal POS tagger: - pos_tag(engine="phayathaibert") runs an ONNX export of the model with ONNX Runtime and the tokenizers library, without PyTorch. The model is downloaded from the Hugging Face Hub, pinned to a commit. Whitespace-only words are tagged PUNCT, and input longer than the model limit is tagged in chunks of whole words. - pos_tag_transformers(engine="phayathaibert", corpus="tud") runs the original model with Transformers. The per-corpus engine tables are merged into one lookup. Add the phayathaibert_onnx optional dependency group, tests, and API documentation. Refs PyThaiNLP#1536
The published tokenizer.json truncates at 510 tokens, so long input was cut before chunking and every word past the cut was tagged X. Turn off the tokenizer's built-in truncation and padding so chunking by whole words takes effect. - Tag words made only of whitespace or format characters (such as the zero-width space) as PUNCT without passing them to the model. - Require onnxruntime>=1.12.0 (opset 17) and tokenizers>=0.19.0 (the Metaspace format in tokenizer.json). - Pin the default revision only for the default repository. - Guard the lazily created tagger with a lock. - Name huggingface-hub in the import check. - List the phayathaibert_onnx extra in the installation notes. - Test tags past the first 510 tokens, an over-long word, and format characters.
- Use D213 docstrings and typed fields in phayathaibert_onnx, and add an __init__ docstring (D107). - Test PhayaThaiBERTTagger, tag() and the new pos_tag and pos_tag_transformers branches with a fake model, so CI covers the new code without onnxruntime, tokenizers or transformers. - Fake every dependency inside patch.dict(sys.modules), so no real module (such as numpy) is imported and then unloaded by the test. - Merge the _chunk_spans tests into one table-driven test.
The model accepts 512 positions, but its accuracy drops sharply from position 415 on, in the original PyTorch model as well as the ONNX export. With chunks of up to 510 tokens, tagging the whole UD Thai-TUD test set as one input gave 80.26% accuracy; with 415 it gives 90.08% (91.21% sentence by sentence). The long-input test now checks that every repeat of a sentence gets the same tags as the sentence alone, which fails with the old limit.
Only README.md changed on the Hugging Face repository; model.onnx, tokenizer.json and config.json are the same files.
- Check dependencies with importlib.util.find_spec instead of unused imports (pylint W0611). - Use a one-line module docstring (pydocstyle D212); the model description moves to the class docstring. - Mark the unused corpus parameter of tag() for SonarCloud (S1172). - Tests: end a docstring with a period (D415), keep one assertion argument order (S3415), and use assertLessEqual (S5906).
CI runs mypy on tests too (mypy 1.19.1, Python 3.9), which rejects calls to the untyped fake model helpers.
Fixes pylint W0404 (reimport) reported by Codacy.
- Write zero-width and special space characters in tests as \u escapes, so they are visible and editors cannot strip them (pylint E2515). - Rename a loop variable that shadowed the module-level tag() (W0621). - Correct the length comment: the model runs on up to 510 tokens.
- Build the truncated word_ids list by unpacking, not concatenation. - Annotate the shared WORDS test attribute as ClassVar.
wiriyabot
force-pushed
the
add-phayathaibert-pos-onnx
branch
from
October 7, 2026 14:15
9cd311c to
9a5da21
Compare
Author
|
@wannaphong Thanks! Rebased onto |
wannaphong
approved these changes
Oct 8, 2026
Member
|
Thank you! |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What do these changes do
Adds nlp-chula/phayathaibert-thai-pos-tagger (UD Thai-TUD, UPOS) to:
pos_tag(words, engine="phayathaibert"): an ONNX export, no PyTorch needed (extraphayathaibert_onnx)pos_tag_transformers(sentence, engine="phayathaibert", corpus="tud"): the original modelWhat was wrong
No engine offered this model.
How this fixes it
PUNCTFixes #1536
Your checklist for this pull request